package nc.ui.test.back.action;

import java.awt.event.ActionEvent;

import nc.itf.uap.pf.busiflow.PfButtonClickContext;
import nc.ui.pub.pf.PfUtilClient;
import nc.ui.pubapp.uif2app.actions.AbstractReferenceAction;
import nc.ui.pubapp.uif2app.funcnode.trantype.TrantypeFuncUtils;
import nc.ui.uif2.editor.IBillCardPanelEditor;
import nc.ui.uif2.model.AbstractAppModel;
import nc.vo.jcom.lang.StringUtil;
import nc.vo.test.back.AggBackVO;

public class AddFromSourceAction extends AbstractReferenceAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2230375376197501627L;
	private IBillCardPanelEditor editor;
	private AbstractAppModel model;

	public void doAction(ActionEvent e) throws Exception {
		editor.getBillCardPanel().getBodyTabbedPane().setSelectedIndex(0);
		PfUtilClient.childButtonClickedNew(createPfButtonClickContext());
		if (PfUtilClient.isCloseOK()) {
			AggBackVO[] vos = (AggBackVO[]) PfUtilClient.getRetVos();

			getTransferViewProcessor().processBillTransfer(vos);

			// setEditable();
		}
	}

	private PfButtonClickContext createPfButtonClickContext() {
		PfButtonClickContext context = new PfButtonClickContext();
		context.setParent(getModel().getContext().getEntranceUI());
		context.setSrcBillType(getSourceBillType());
		context.setPk_group(getModel().getContext().getPk_group());
		context.setUserId(getModel().getContext().getPk_loginUser());

		String vtrantype = TrantypeFuncUtils.getTrantype(getModel()
				.getContext());

		if (StringUtil.isEmptyWithTrim(vtrantype)) {
			context.setCurrBilltype("AHH2");
		} else {
			context.setCurrBilltype(vtrantype);
		}

		context.setUserObj(null);
		context.setSrcBillId(null);
		context.setBusiTypes(getBusitypes());

		context.setTransTypes(getTranstypes());

		context.setClassifyMode(-1);
		return context;
	}

	public IBillCardPanelEditor getEditor() {
		return editor;
	}

	public void setEditor(IBillCardPanelEditor editor) {
		this.editor = editor;
	}

	public AbstractAppModel getModel() {
		return model;
	}

	public void setModel(AbstractAppModel model) {
		this.model = model;
	}

}
